package org.ru.mse10.cvis.web.bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.convert.EnumConverter;
import javax.faces.model.SelectItem;

import org.ru.mse10.cvis.constants.UserRole;
import org.ru.mse10.cvis.entity.util.CustomFieldType;

/**
 * The Class SelectItemsBean.
 */
@ApplicationScoped
@ManagedBean(name = "selectItemsBean")
public class SelectItemsBean {

	/** The user role converter. */
	private EnumConverter userRoleConverter = new EnumConverter(UserRole.class);

	/** The custom fields type converter. */
	private EnumConverter customFieldsTypeConverter = new EnumConverter(
			CustomFieldType.class);

	/**
	 * Gets the custom field types as select items.
	 * 
	 * @return the custom field types as select items
	 */
	public List<SelectItem> getCustomFieldTypesAsSelectItems() {
		List<SelectItem> items = new ArrayList<SelectItem>();
		for (CustomFieldType type : CustomFieldType.values()) {
			items.add(new SelectItem(type, type.getLabel()));
		}
		return items;
	}

	/**
	 * Gets the user roles.
	 * 
	 * @return the user roles
	 */
	public ArrayList<SelectItem> getUserRoles() {
		ArrayList<SelectItem> items = new ArrayList<SelectItem>(
				UserRole.values().length);
		for (UserRole g : UserRole.values()) {
			items.add(new SelectItem(g, g.getLabel()));
		}
		return items;
	}

	// ---------get/set

	/**
	 * Gets the user role converter.
	 * 
	 * @return the user role converter
	 */
	public EnumConverter getUserRoleConverter() {
		return userRoleConverter;
	}

	/**
	 * Sets the user role converter.
	 * 
	 * @param userRoleConverter
	 *            the new user role converter
	 */
	public void setUserRoleConverter(EnumConverter userRoleConverter) {
		this.userRoleConverter = userRoleConverter;
	}

	/**
	 * Gets the custom fields type converter.
	 * 
	 * @return the custom fields type converter
	 */
	public EnumConverter getCustomFieldsTypeConverter() {
		return customFieldsTypeConverter;
	}

	/**
	 * Sets the custom fields type converter.
	 * 
	 * @param customFieldsTypeConverter
	 *            the new custom fields type converter
	 */
	public void setCustomFieldsTypeConverter(
			EnumConverter customFieldsTypeConverter) {
		this.customFieldsTypeConverter = customFieldsTypeConverter;
	}
}
